package scuts.core.extensions;
import scuts.core.types.LazyIterator;
import scuts.core.Lazy;
using scuts.core.Lazy;

class LazyIterators 
{

  public static function cons<T>(l:LazyIterator<T>, t:T):LazyIterator<T> 
  {
    return function () {
      var first = true;
      var iter:LazyIterator<T> = LazyExpr.lazy(l());
      return {
        hasNext : function () {
          return first || { iter().hasNext();};
        },
        next: function () {
          return if (first) {first = false; t;} else iter().next();
        }
      }
    }
  }
  
}